package oop.ex2.expression;

import oop.ex2.exceptions.UnrecognizedVariable;

public class PowerFunctionNode extends FunctionNode {
	private static final int NUMBER_OF_PARAMS = 2;
	private static boolean BOUNDED_PARAMETERS = true;
	
	/**
	 * Build a function node.
	 * @param matchedString The string that caused this function to be created.
	 */
	public PowerFunctionNode(String matchedString) {
		super(matchedString, NUMBER_OF_PARAMS, BOUNDED_PARAMETERS);
	}

	@Override
	public double calculateNode() throws UnrecognizedVariable {
		double output = (double) Math.pow(_children.get(0).calculateNode() , _children.get(1).calculateNode());

		if (Double.isNaN(output) || Double.isInfinite(output))
			throw new ArithmeticException("Illegal input to power.");
		return output;
	}

}
